package com.redis.lock;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.locks.Lock;

/**
 * @Description
 * @Author lizhilong
 * @Date 2020/12/7 22:56
 */
@Component
public class LockType {
    @Resource
    private RedissonClient redissonClient;

    public RLock getLock(boolean fair, String lockKey) {
        if (fair) {
            return redissonClient.getFairLock(lockKey);
        } else {
            return redissonClient.getLock(lockKey);
        }
    }
}
